<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2023/5/8
 * Time: 15:52
 */

namespace app\api\controller;
use app\common\controller\Api;
use think\Db;
use think\Request;
class Teacher extends Api
{
    protected $noNeedLogin = [''];
    protected $noNeedRight = '*';


    //乘车打卡
    public function riding()
    {
        if (!Request::instance()->isGet())
        {
            $this->error('请求方式错误');
        }
        $info = $this->auth->getUserinfo();

        $params = input('get.');
        $where = [];
        if(isset($params['circuit_id']) && $params['circuit_id']!='')
        {
            $where['b.circuit_id'] = $params['circuit_id'];
        }
        $circuit = Db::name('circuit')->select();
        $circuit_arr = [];
        foreach ($circuit as $k=>$v)
        {
            $circuit_arr[$v['id']] = $v;
        }
        //dump($class_arr);exit;

        $student = Db::name('student_information')->where('class_room_id',$info['class_room_id'])->select();

        $student_arr = [];
        if($student)
        {
            foreach ($student as $k=>$v)
            {
                $student_arr[$v['RC_NUM']] = $v;
            }
        }
        $leave = Db::name('leave')->field('student_id,createtime')->select();//->where('time',date('Y-m-d'))
        $leave_arr = [];
        if($leave)
        {
            foreach ($leave as $k=>$v)
            {
                $leave_arr[$v['student_id']] = $v;
            }
        }

        $student = Db::name('automatic_student')->alias('a')
            //->join('fa_on_off_car b','a.RC_NUM=b.RC_NUM','left')
            ->join('fa_student_information b','a.RC_NUM=b.RC_NUM')
            ->where(['a.class_room_id'=>$info['class_room_id']])
            ->where($where)
            //->field('a.student_id,a.RC_NUM,a.class_room_id,a.state,b.RC_TYPE,b.circuit,b.type,b.site,b.class_room,b.TIME')
            ->field('a.student_id,a.RC_NUM,a.class_room_id,a.state,b.name,b.student_number,b.circuit_id,b.point')
            ->select();
        if(!$student)
        {
            $this->error('暂无数据');
        }
        $on  = ['on'=>['data'=>[],'total'=>['on'=>0,'ont'=>0,'leave'=>0]],'off'=>['data'=>[],'total'=>['on'=>0,'ont'=>0,'leave'=>0]]];
        $off = ['on'=>['data'=>[],'total'=>['on'=>0,'ont'=>0,'leave'=>0]],'off'=>['data'=>[],'total'=>['on'=>0,'ont'=>0,'leave'=>0]]];

        if($student)
        {
            $on  = ['on'=>['data'=>$student,'total'=>['on'=>0,'ont'=>0,'leave'=>0]],'off'=>['data'=>$student,'total'=>['on'=>0,'ont'=>0,'leave'=>0]]];
            $off = ['on'=>['data'=>$student,'total'=>['on'=>0,'ont'=>0,'leave'=>0]],'off'=>['data'=>$student,'total'=>['on'=>0,'ont'=>0,'leave'=>0]]];
        }

        $on_off_car = Db::name('on_off_car')->select();//->where('DTIME',date('Y-m-d'))

        $off_car_arr = [];
        if($on_off_car)
        {
            foreach ($on_off_car as $k=>$v)
            {
                $off_car_arr[$v['RC_NUM'].'-'.$v['type'].'-'.$v['RC_TYPE']] = $v;
            }
        }


        foreach ($on as $k1=>$v1)
        {

            foreach ($v1['data'] as $k2=>&$v2)
            {
                $on[$k1]['data'][$k2]['TIME'] = '';
                $on[$k1]['data'][$k2]['circuit'] = isset($circuit_arr[$v2['circuit_id']])?$circuit_arr[$v2['circuit_id']]['title']:'';
               if($k1=='on')
               {
                   $isset = $v2['RC_NUM'].'-1-1';
               }
               else
               {
                   $isset = $v2['RC_NUM'].'-1-2';
               }
                $on[$k1]['data'][$k2]['status'] = 3;
                if(isset($leave_arr[$v2['student_id']]) )
                {
                    $on[$k1]['data'][$k2]['status'] = 2;
                    $on[$k1]['data'][$k2]['TIME'] = date('H:i',$leave_arr[$v2['student_id']]['createtime']);
                }
                if(isset($off_car_arr[$isset]))
                {
                    $on[$k1]['data'][$k2]['status'] =0;
                    $on[$k1]['data'][$k2]['TIME'] = date('H:i',$off_car_arr[$isset]['TIME']);
                    $on[$k1]['data'][$k2]['circuit'] = $off_car_arr[$isset]['circuit'];
                    $on[$k1]['data'][$k2]['point'] = $off_car_arr[$isset]['site'];
                }


                if($on[$k1]['data'][$k2]['status']==3)
                {
                    $on[$k1]['total']['ont']+=1;
                }
                else if($on[$k1]['data'][$k2]['status']==0)
                {
                    $on[$k1]['total']['on']+=1;
                }
                else
                {
                    $on[$k1]['total']['leave']+=1;
                }

            }
        }
        //dump($on);exit;
        array_multisort(array_column($on['on']['data'], 'status'),SORT_DESC,$on['on']['data']);
        array_multisort(array_column($on['off']['data'], 'status'),SORT_DESC,$on['off']['data']);

        foreach ($off as $k1=>$v1)
        {

            foreach ($v1['data'] as $k2=>&$v2)
            {
                $off[$k1]['data'][$k2]['TIME'] = '';
                $off[$k1]['data'][$k2]['circuit'] = isset($circuit_arr[$v2['circuit_id']])?$circuit_arr[$v2['circuit_id']]['title']:'';
                if($k1=='on')
                {
                    $isset = $v2['RC_NUM'].'-2-1';
                }
                else
                {
                    $isset = $v2['RC_NUM'].'-2-2';
                }
                $off[$k1]['data'][$k2]['status'] = 3;

                if(isset($leave_arr[$v2['student_id']]))
                {

                    $off[$k1]['data'][$k2]['status'] = 2;
                    $off[$k1]['data'][$k2]['TIME'] = date('H:i',$leave_arr[$v2['student_id']]['createtime']);
                }
                if(isset($off_car_arr[$isset]))
                {

                    $off[$k1]['data'][$k2]['status'] =0;
                    $off[$k1]['data'][$k2]['TIME'] = date('H:i',$off_car_arr[$isset]['TIME']);
                    $off[$k1]['data'][$k2]['circuit'] = $off_car_arr[$isset]['circuit'];
                    $off[$k1]['data'][$k2]['point'] = $off_car_arr[$isset]['site'];
                }

                if($off[$k1]['data'][$k2]['status']==3)
                {
                    $off[$k1]['total']['ont']+=1;
                }
                else if($off[$k1]['data'][$k2]['status']==0)
                {
                    $off[$k1]['total']['on']+=1;
                }
                else
                {
                    $off[$k1]['total']['leave']+=1;
                }

            }
        }
        array_multisort(array_column($off['on']['data'], 'status'),SORT_DESC,$off['on']['data']);
        array_multisort(array_column($off['off']['data'], 'status'),SORT_DESC,$off['off']['data']);

        $this->success('',['on'=>$on,'off'=>$off]);

    }

    //查看线路
    public function circuit()
    {
        if (!Request::instance()->isGet())
        {
            $this->error('请求方式错误');
        }
        $list = Db::name('circuit')->field('id,title,circuit')->select();
        if($list)
        {
            foreach ($list as $k=>&$v)
            {
                $v['circuit'] = json_decode($v['circuit'],true);
            }
        }
        $this->success('',$list);
    }

    //消息
    public function message()
    {
        if (!Request::instance()->isGet())
        {
            $this->error('请求方式错误');
        }
        $time = date('Y-m-d');
        $userInfo = $this->auth->getUserinfo();

        $params = input('get.');
        $where = [];
        //$where['a.DTIME'] = $time;
        /*if(isset($params['class_room_id']) && $params['class_room_id']!='')
        {
            $where['b.class_room_id'] = $params['class_room_id'];
        }
        if(isset($params['circuit_id']) &&$params['circuit_id']!='')
        {
            $where['c.id'] = $params['circuit_id'];
        }*/
        $cars = Db::name('car')->field('IMEI,license_plate')->where("IMEI!=''")->select();
        $cars_arr = [];
        if($cars)
        {
            foreach ($cars as $key=>$value)
            {
                $cars_arr[$value['IMEI']] = $value['license_plate'];
            }
        }

        $class_room = Db::name('class_room')->select();
        $room_arr = [];
        if($class_room)
        {
            foreach ($class_room as $key=>$value)
            {
                $room_arr[$value['id']] = $value['title'];
            }
        }
        $circuit = Db::name('circuit')->field('id,title')->select();

        $circuit_arr = [];
        if($circuit)
        {
            foreach ($circuit as $key=>$value)
            {
                $circuit_arr[$value['id']] = $value['title'];
            }
        }
        $where['b.class_room_id'] = $userInfo['class_room_id'];

        $list = Db::name('on_off_car')->alias('a')
            ->join('fa_student_information b','a.RC_NUM=b.RC_NUM','inner')
            //->join('fa_circuit c','a.circuit_id=c.id')
            ->where($where)
            //->field('b.name,b.class_room_id,b.student_number,a.RC_TYPE,a.TIME,c.title')->select();
            ->field('b.name,b.class_room_id,a.RC_TYPE,a.TIME,b.circuit_id,a.IMEI')
            //->fetchSql(true)
            ->select();
         //dump($list);exit;
        if($list)
        {
            foreach ($list as $k=>&$v)
            {

                $v['on_time'] = date('Y-m-d H:i:s',$v['TIME']);
                $v['class_room'] = isset($room_arr[$v['class_room_id']])?$room_arr[$v['class_room_id']]:'';
                $v['circuit'] = isset($circuit_arr[$v['circuit_id']])?$circuit_arr[$v['circuit_id']]:'';
                $v['license_plate'] = isset($cars_arr[$v['IMEI']])?$cars_arr[$v['IMEI']]:'';
                $v['status'] = '丢卡';
            }
            $this->success('',$list);
        }
        else
        {
            $this->error('暂无数据',[]);
        }

    }

    //获取学生列表
    public function students()
    {
        if (!Request::instance()->isGet())
        {
            $this->error('请求方式错误');
        }
        $info = $this->auth->getUserinfo();
        $list = Db::name('student_information')->field('id,name')->where('class_room_id',$info['class_room_id'])->select();
        if($list)
        {
            $this->success('',$list);
        }
        else
        {
            $this->error('暂无数据');
        }
    }

    //获取学生数量
    public function get_total()
    {
        if (!Request::instance()->isGet())
        {
            $this->error('请求方式错误');
        }

        $info = $this->auth->getUserinfo();
        $list = Db::name('student_information')->field('id,name')->where('class_room_id',$info['class_room_id'])->count('id');

       $this->success('',intval($list));

    }

    //班级学生
    public function get_class_student()
    {
        if (!Request::instance()->isGet())
        {
            $this->error('请求方式错误');
        }

        $params = input('get.');
        $where = [];
        if(isset($params['circuit_id']) && $params['circuit_id']!='')
        {
            $where['a.circuit_id'] = $params['circuit_id'];
        }

        $info = $this->auth->getUserinfo();
        $list = Db::name('student_information')->alias('a')
                ->join('fa_circuit b','a.circuit_id=b.id')
                ->where($where)
                ->field('a.id,a.name,a.student_number,a.circuit_id,b.title')->where('a.class_room_id',$info['class_room_id'])
                ->select();
        if($list)
        {
            $this->success('',$list);
        }
        else
        {
            $this->error('暂无数据');
        }
    }

    //切换线路
    public function save_circuit()
    {
        if (!Request::instance()->isPost())
        {
            $this->error('请求方式错误');
        }

        $params = input('post.');
        $info = $this->auth->getUserinfo();
        if(!isset($params['id']) && $params['id']=='' )
        {
            $this->error('缺少参数');
        }
        if(!isset($params['circuit_id']) && $params['circuit_id']=='' )
        {
            $this->error('缺少参数');
        }

        $res = Db::name('student_information')->where(['id'=>$params['id'],'class_room_id'=>$info['class_room_id']])->update(['circuit_id'=>$params['circuit_id']]);
        if($res!==false)
        {
            $this->success('','切换成功');
        }
        else
        {
            $this->error('切换失败');
        }
    }

    //班级管理
    public function ride_management()
    {
        if (!Request::instance()->isGet())
        {
            $this->error('请求方式错误');
        }
        $info = $this->auth->getUserinfo();
        $list = Db::name('student_information')->alias('a')
                ->join('fa_circuit b','a.circuit_id=b.id')
                ->where(['a.class_room_id'=>$info['class_room_id']])
                ->field('a.id,a.name,a.circuit_id,a.student_number,b.title')
                ->select();

        $data = [];
        if($list)
        {
            foreach ($list as $k=>&$v)
            {
                $arr = [];
                $arr['circuit_id'] = $v['circuit_id'];
                $arr['title'] = $v['title'];

                if(!isset($data[$v['circuit_id']]))
                {
                    $data[$v['circuit_id']] = $arr;
                }
                $v['status'] = false;
                $data[$v['circuit_id']]['chile'][] = $v;

            }
        }
        if($data)
        {
            $this->success('',$data);
        }
        else
        {
            $this->error('暂无数据');
        }
    }

    //班级管理new
    public function new_management()
    {
        if (!Request::instance()->isGet()) {
            $this->error('请求方式错误');
        }
        $params = input('get.');
        if (!isset($params['circuit_id']) && $params['circuit_id'] == '')
        {
            $this->error('缺少参数');
        }
        if (!isset($params['point']) && $params['point'] == '')
        {
            $this->error('缺少参数');
        }

        $info = $this->auth->getUserinfo();

        $list = Db::name('student_information')->field("id,name")->where(['circuit_id'=>$params['circuit_id'],'class_room_id'=>$info['class_room_id'],'point'=>$params['point']])->select();

        if($list)
        {
            foreach ($list as $k=>&$v)
            {
                $v['status'] = false;
            }
            $this->success('',$list);
        }
        else
        {
            $this->error('暂无数据');
        }
    }

    //待选人员
    public function be_selected()
    {
        if (!Request::instance()->isGet())
        {
            $this->error('请求方式错误');
        }
        $info = $this->auth->getUserinfo();
        $list = Db::name('student_information')->field('id,name')->where(['circuit_id'=>0,'class_room_id'=>$info['class_room_id']])->select();
        if($list)
        {
            foreach ($list as $k=>&$v)
            {
                $v['status'] = false;
            }
            $this->success('',$list);
        }
        else
        {
            $this->error('暂无数据');
        }
    }

    public function add()
    {
        if (!Request::instance()->isPost())
        {
            $this->error('请求方式错误');
        }

        $params = input('post.');

        if(!isset($params['status']) && $params['status']=='')
        {
            $this->error('缺少参数');
        }
        if(!isset($params['circuit_id']) && $params['circuit_id']=='')
        {
            $this->error('缺少参数');
        }
        if(!isset($params['user_id']) && $params['user_id']=='')
        {
            $this->error('缺少参数');
        }
        if(!isset($params['point']) && $params['point']=='')
        {
            $this->error('缺少参数');
        }


        //dump($params);
        $data = [];
        $user_id = explode(',',$params['user_id']);
        $student = new \app\admin\model\StudentInformation;
        foreach ($user_id as $k=>$v)
        {
            $arr = [];
            $arr['id'] = $v;
            if($params['status']==1)
            {
                $arr['circuit_id'] = $params['circuit_id'];
            }
            else
            {
                $arr['circuit_id'] = 0;
            }
            $arr['point'] = $params['point'];
            $data[] = $arr;
        }
        $res = $student->saveAll($data);

        if($res)
        {
            $this->success('分配成功');
        }
        else
        {
            $this->error('分配失败');
        }
    }

    //请假
    public function leave()
    {
        if (!Request::instance()->isPost())
        {
            $this->error('请求方式错误');
        }
        $id = $this->auth->id;
        $info = $this->auth->getUserinfo();
        $params = input('post.');
        if($params['student_id']=='')
        {
            $this->error('请假学生不能为空');
        }
        if($params['status']=='')
        {
            $this->error('请假理由不能为空');
        }
        if($params['start_time']=='')
        {
            $this->error('开始时间不能为空');
        }
        if($params['end_time']=='')
        {
            $this->error('结束时间不能为空');
        }
        if($params['day']=='')
        {
            $this->error('时长不能为空');
        }
        if($params['content']=='')
        {
            $this->error('请假理由不能为空');
        }
        $time = time();
        $params['start_time'] = strtotime($params['start_time']);
        $params['end_time'] = strtotime($params['end_time']);
        $params['apply_id'] = $id;
        $params['role'] = $info['role'];
        $params['createtime'] = $time;
        $params['updatetime'] = $time;
        $res = Db::name('leave')->insert($params);
        if($res)
        {
            $this->success('提交成功');
        }
        else
        {
            $this->error('提交失败');
        }
    }

    //请假列表
    public function leave_list()
    {
        if (!Request::instance()->isGet())
        {
            $this->error('请求方式错误');
        }
        $params = input('get.');
        if(!isset($params['state']) || $params['state']=='')
        {
            $this->error('缺少参数');
        }
        $where = [];
        if(isset($params['name']) && $params['name']!='')
        {
            $where['b.name'] = $params['name'];
        }
        $userInfo = $this->auth->getUserinfo();
        $list = Db::name('leave')->alias('a')
            ->join('fa_student_information b','a.student_id=b.id')
            ->field('a.*,b.name')
            ->where(['b.class_room_id'=>$userInfo['class_room_id'],'a.state'=>$params['state']])
            ->where($where)
            ->paginate($params['listRows'],false,['page'=>$params['page']])->toArray();

        if($list['data'])
        {
            foreach ($list['data'] as $k=>&$v)
            {

                $v['start_time'] = date('Y-m-d H:i',$v['start_time']);
                $v['end_time'] = date('Y-m-d H:i',$v['end_time']);
                $v['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
                $v['approval_time'] = date('Y-m-d H:i:s',$v['approval_time']);
            }
        }
        $this->success('',$list);

    }

    //请假审核
    public function examine()
    {
        if (!Request::instance()->isPost())
        {
            $this->error('请求方式错误');
        }
        $id = $this->auth->id;
        $params = input('post.');
        if(!isset($params['id']) && $params['id']=='')
        {
            $this->error('缺少参数');
        }
        if(!isset($params['state']) && $params['state']=='')
        {
            $this->error('缺少参数');
        }
        $data = [];
        $data['state'] = $params['state'];
        $data['approval_id'] = $id;
        $data['approval_time'] = time();
        $data['reject_content'] = $params['reject_content'];

        $res = Db::name('leave')->where('id',$params['id'])->update($data);
        if($res)
        {
            $this->success('审核成功');
        }
        else
        {
            $this->error('审核失败');
        }
    }

    //打卡记录
    public function record()
    {

        if (!Request::instance()->isGet())
        {
            $this->error('请求方式错误');
        }
        $time = date('Y-m-d');
        $userInfo = $this->auth->getUserinfo();

        $params = input('get.');
        $where = [];
        //$where['a.DTIME'] = $time;
        /*if(isset($params['class_room_id']) && $params['class_room_id']!='')
        {
            $where['b.class_room_id'] = $params['class_room_id'];
        }
        if(isset($params['circuit_id']) &&$params['circuit_id']!='')
        {
            $where['c.id'] = $params['circuit_id'];
        }*/

        $cars = Db::name('car')->field('IMEI,license_plate')->where("IMEI!=''")->select();
        $cars_arr = [];
        if($cars)
        {
            foreach ($cars as $key=>$value)
            {
                $cars_arr[$value['IMEI']] = $value['license_plate'];
            }
        }

        $class_room = Db::name('class_room')->select();
        $room_arr = [];
        if($class_room)
        {
            foreach ($class_room as $key=>$value)
            {
                $room_arr[$value['id']] = $value['title'];
            }
        }
        $circuit = Db::name('circuit')->field('id,title')->select();

        $circuit_arr = [];
        if($circuit)
        {
            foreach ($circuit as $key=>$value)
            {
                $circuit_arr[$value['id']] = $value['title'];
            }
        }
        $where['b.class_room_id'] = $userInfo['class_room_id'];
        if(isset($params['circuit_id']) && $params['circuit_id']!='')
        {
            $where['b.circuit_id'] = $params['circuit_id'];
        }
        $list = Db::name('on_off_car')->alias('a')
            ->join('fa_student_information b','a.RC_NUM=b.RC_NUM','inner')
            ->where($where)
            ->field('b.name,b.class_room_id,a.RC_TYPE,a.TIME,a.circuit_id,a.IMEI')
            ->select();

        if($list)
        {
            foreach ($list as $k=>&$v)
            {

                $v['on_time'] = date('Y-m-d H:i:s',$v['TIME']);
                $v['class_room'] = isset($room_arr[$v['class_room_id']])?$room_arr[$v['class_room_id']]:'';
                $v['circuit'] = isset($circuit_arr[$v['circuit_id']])?$circuit_arr[$v['circuit_id']]:'';
                $v['license_plate'] = isset($cars_arr[$v['IMEI']])?$cars_arr[$v['IMEI']]:'';
                //$v['status'] = '丢卡';
            }
            $this->success('',$list);
        }
        else
        {
            $this->error('暂无数据',[]);
        }
    }

    public function student()
    {
        if (!Request::instance()->isGet())
        {
            $this->error('请求方式错误');
        }
        $params = input('get.');

        $list = Db::name('student_information')->field('id,name')->where(['name'=>['like','%'.$params['name'].'%']])->select();
        if($list)
        {
            $this->success('',$list);
        }
        else
        {
            $this->error('暂无数据');
        }
    }

    public function get_car()
    {
        if (!Request::instance()->isGet())
        {
            $this->error('请求方式错误');
        }
        $params = input('get.');
        if(!isset($params['type']) || $params['type']=='')
        {
            $this->error('缺少参数');
        }
        $userInfo = $this->auth->getUserinfo();
        $data = [];
        if($params['type']==1)
        {
            $list = Db::name('student_information')->alias('a')
                ->join('fa_circuit b','a.circuit_id=b.id')
                ->field('b.car_id')
                ->group('b.car_id')
                ->where(['a.class_room_id'=>$userInfo['class_room_id']])
                ->select();
            $list_arr = [];
            if($list)
            {
                foreach ($list as $k=>$v)
                {
                    $list_arr[$v['car_id']] = $v['car_id'];
                }
            }

            $car = Db::name('car')->field('id,license_plate,pinyin,IMEI')->where("IMEI!=''")->select();

            if($car)
            {
                foreach ($car as $k=>$v)
                {
                    if(isset($list_arr[$v['id']]))
                    {
                        $data[] = $v;
                    }
                }
            }
        }
        else if($params['type']==2)
        {
            $list = Db::name('student_information')->alias('a')
                ->join('fa_circuit b','a.circuit_id=b.id')
                ->join('fa_car c','b.car_id=c.id')
                ->field('c.id,c.license_plate,c.pinyin,c.IMEI')
                ->where('a.parent_id',$userInfo['id'])
                ->select();
            $data = $list;

        }


        if($data)
        {
            $this->success('',$data);
        }
        else
        {
            $this->error('暂无数据');
        }

    }

    //候车点名
    public function waiting()
    {
        if (!Request::instance()->isGet())
        {
            $this->error('请求方式错误');
        }
        $params = input('get.');
        $userInfo = $this->auth->getUserinfo();
        $where = [];
        if(!isset($params['circuit_id']) || $params['circuit_id']=='')
        {
            $this->error('缺少参数');
        }
        $student_information = Db::name('student_information')->select();//->where([''])
        $student_arr = [];
        if($student_information)
        {
            foreach ($student_information as $k=>$v)
            {
                $student_arr[$v['id']] = $v;
            }
        }
        $leave = Db::name('leave')->field('student_id,createtime')->select();//->where('time',date('Y-m-d'))
        $leave_arr = [];
        if($leave)
        {
            foreach ($leave as $k=>$v)
            {
                $leave_arr[$v['student_id']] = $v;
            }
        }

        $where['a.circuit_id'] = $params['circuit_id'];
        $where['class_room_id'] = $userInfo['class_room_id'];
        //$where['b.DTIME'] = date('Y-m-d');
        $list = Db::name('automatic_student')->alias('a')
                ->join('fa_on_off_waiting b','a.RC_NUM=b.RC_NUM','left')
                ->where($where)
                ->field('a.student_id,a.class_room_id,a.student_id,b.RC_TYPE')
                ->select();

        if($list)
        {

            foreach ($list as $key=>&$value)
            {

                $type = 2;
                if($value['RC_TYPE']==null)
                {
                    $value['status'] = '未签到';
                }

                if(isset($leave_arr[$value['student_id']]))
                {
                    $type = 3;
                }

                if($value['RC_TYPE']!=null)
                {
                    $type = 1;
                    $value['status'] = '已签到';
                }
                $value['name'] = '';
                $value['student_number'] = '';
                $value['type'] = $type;
                if(isset($student_arr[$value['student_id']]))
                {
                    $value['name'] = $student_arr[$value['student_id']]['name'];
                    $value['student_number'] = $student_arr[$value['student_id']]['student_number'];
                }
            }
            array_multisort(array_column($list, 'type'),SORT_DESC,$list);
            $this->success('',$list);
        }

        $this->error('暂无数据');

    }
}